﻿using System;
using System.Runtime.Serialization;

using Xunit;
using FluentAssertions;

using Unity.Environment.Exceptions;

namespace Unity.Commons.Tests.Exceptions
{
    public class EnvironmentParameterNotFoundExceptionTest
    {
        private const string testErrorMessage = "Can't found environment parameter";
        private const string testParameterName = "testParameterName";
        [Fact]
        public void CatchExceptionTest()
        {
            Assert.ThrowsAsync<EnvironmentParameterNotFoundException>(() =>
            throw new EnvironmentParameterNotFoundException());

            Assert.ThrowsAsync<EnvironmentParameterNotFoundException>(() => 
            throw new EnvironmentParameterNotFoundException(testErrorMessage, testParameterName));
        }

        [Fact]
        public void SerializeExceptionTest()
        {
            EnvironmentParameterNotFoundException testException = 
                new EnvironmentParameterNotFoundException(testErrorMessage, testParameterName);
            testException.Should().BeBinarySerializable();

            SerializationInfo serializationInfo = new SerializationInfo(typeof(EnvironmentParameterNotFoundException),
                new FormatterConverter());
            StreamingContext streamingContext = new StreamingContext();

            testException.GetObjectData(serializationInfo, streamingContext);
        }
    }
}
